/****************************************************
          File Name:thread.c
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Sat 16 Aug 2014 10:15:33 AM CST
*****************************************************/

#include<stdio.h>
#include<pthread.h>
#include<stdlib.h>
#include<unistd.h>
#include<errno.h>

pthread_t gtid; // global thread id

void er(char *fun)
{
    perror(fun);
    exit(errno);
}

void pshow(const char *s)
{
    pid_t pid;
    pthread_t tid;

    pid=getpid();
    tid=pthread_self();

    printf("%s pid %u tid %u (0x%x)\n",s,(unsigned int)pid,(unsigned int)tid,(unsigned int)tid);
}

void *pfun(void *arg)
{
    pshow("new thread: ");
    return ((void *)0);
}

int main(int argc,char *argv[])
{
    pthread_create(&gtid,NULL,&pfun,NULL);
    pshow("main thread: ");
    sleep(3);
    return 0;
}
